<?php

include('aop/AOPProvider.class.php');
include('aop/AOPProxy.class.php');
include('classes/Test.class.php');

// array config example
$points1 = array(
	array(
		'point' => array('class'=>'Test','method'=>'insert'),
		'event'	 => 'before',
		'advice'=> array('adviceController','insert')
	),
	array(
		'point' => array('class'=>'Test','method'=>'update'),
		'event'	 => 'before',
		'advice'=> array('adviceController','update')
	),
	array(
		'point' => array('class'=>'Test','method'=>'save'),
		'event'	 => 'before',
		'advice'=> array('adviceController','save')
	),
);

// one more array config example
$points2 = array(
	array(
		'point' => array('class'=>'Test','method'=>'insert'),
		'event'	 => 'after',
		'advice'=> array('adviceController2','insert')
	),
	array(
		'point' => array('class'=>'Test','method'=>'update'),
		'event'	 => 'after',
		'advice'=> array('adviceController2','update')
	),
	array(
		'point' => array('class'=>'Test','method'=>'save'),
		'event'	 => 'after',
		'advice'=> array('adviceController2','save')
	),
);

// crearing AOPProvider
$AOPProvider = new AOPProvider();
$AOPProvider->addConfig($points1)
				->addConfig($points2)
				->addConfig('config/Test.aop.xml');
				
// sample of creating class 
$test = new AOPProxy('Test');

$test->insert('p1', 'p2');
$test->update('p1');
$test->save();

$testClass = new Test();

$test2 = new AOPProxy($testClass);

$test2->insert('p1', 'p2');
$test2->update('p1');
$test2->save();


// handlers
function insert_before_hdl($param1, $param2) {
	echo 'insert_before_hdl('.$param1.','.$param2.')<br>';
}

function insert_after_hdl($param1, $param2) {
	echo 'insert_after_hdl('.$param1.','.$param2.')<br>';
}

function update_before_hdl($param1) {
	echo 'update_before_hdl('.$param1.')<br>';
}

function update_after_hdl($param1) {
	echo 'update_after_hdl('.$param1.')<br>';
}

function save_before_hdl() {
	echo 'save_before_hdl('.')<br>';
}

function save_after_hdl() {
	echo 'save_after_hdl('.')<br>';
}

class adviceController {
	
	function insert($param1, $param2) {
		echo 'adviceController::insert('.$param1.','.$param2.')<br>';	
	}
	
	function update($param1) {
		echo 'adviceController::update('.$param1.')<br>';
	}
	
	function save() {
		echo 'adviceController::save()<br>';
	}
	
}


class adviceController2 {
	
	static function insert($param1, $param2) {
		echo 'adviceController2::insert('.$param1.','.$param2.')<br>';	
	}
	
	static function update($param1) {
		echo 'adviceController2::update('.$param1.')<br>';
	}
	
	static function save() {
		echo 'adviceController2::save()<br>';
	}
	
}

$adviceController = new adviceController();